package cn.tedu.jsd2210.csmall.product.controller;

import cn.tedu.jsd2210.csmall.product.pojo.dto.BrandAddNewDto;
import cn.tedu.jsd2210.csmall.product.pojo.dto.BrandUpdateDto;
import cn.tedu.jsd2210.csmall.product.pojo.dto.CategoryAddNewDto;
import cn.tedu.jsd2210.csmall.product.pojo.dto.CategoryUpdateDto;
import cn.tedu.jsd2210.csmall.product.pojo.entity.Brand;
import cn.tedu.jsd2210.csmall.product.pojo.vo.BrandListItemVO;
import cn.tedu.jsd2210.csmall.product.pojo.vo.BrandStandardVO;
import cn.tedu.jsd2210.csmall.product.pojo.vo.CategoryListItemVO;
import cn.tedu.jsd2210.csmall.product.pojo.vo.CategoryStandardVO;
import cn.tedu.jsd2210.csmall.product.service.IBrandService;
import cn.tedu.jsd2210.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/brands")
@Api(tags="01.品牌管理模块")
@Validated
public class BrandController {
    @Autowired
    private IBrandService brandService;
//http://localhost:9080/brands/add-new
    @ApiOperation("添加品牌")
    @PostMapping("/add-new")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid BrandAddNewDto brandAddNewDto){
            log.debug("开始处理添加品牌的请求,参数:{}",brandAddNewDto);
        brandService.addNew(brandAddNewDto);
            return JsonResult.ok();
    }
    //http://localhost:9080/brands/{?}/delete
    @ApiOperation("根据ID删除品牌")
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "品牌ID", required = true, dataType = "long")
    })
    public JsonResult<Void> delete(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id){
        log.debug("开始处理添加品牌的请求,参数:{}",id);
        brandService.delete(id);
        return JsonResult.ok();
    }
    //http://localhost:9080/brands/{?}/update
    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改品牌")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name="id",value = "品牌ID",required = true,dataType = "long",example = "100")
    public JsonResult<Void> updateInfoById(@PathVariable @Range(min = 1L,message = "请提交有效的ID值!") Long id,
                                           @Valid BrandUpdateDto brandUpdateDto){
        log.debug("开始处理根据id{}修改品牌的请求,新数据:{}",id,brandUpdateDto);
        brandService.updateInfoById(brandUpdateDto,id);
        return JsonResult.ok();
    }
    //http://localhost:9080/brands/{?}/enable
    @PostMapping("/{id:[0-9]+}/enable")
    @ApiOperation("启用品牌")
    @ApiOperationSupport(order = 310)
//    @ApiImplicitParams({
    @ApiImplicitParam(name="id",value = "品牌ID",required = true,dataType = "long",example = "100")
//        ,@ApiImplicitParam(name="username",value = "测试多参数用户名",required = true,dataType = "string")
//    })
    public JsonResult<Void> setEnable(@PathVariable @Range(min = 1L,message = "请提交有效的ID值!") Long id){
        log.debug("开始处理根据修改品牌状态的请求,参数:{}",id);
        brandService.setEnable(id);
        return JsonResult.ok();
    }

    //http://localhost:9080/brands/{?}/disable
    @PostMapping("/{id:[0-9]+}/disable")
    @ApiOperation("禁用品牌")
    @ApiOperationSupport(order = 311)
//    @ApiImplicitParams({
    @ApiImplicitParam(name="id",value = "品牌ID",required = true,dataType = "long",example = "100")
//        ,@ApiImplicitParam(name="username",value = "测试多参数用户名",required = true,dataType = "string")
//    })
    public JsonResult<Void> setDisable(@PathVariable @Range(min = 1L,message = "请提交有效的ID值!") Long id){
        log.debug("开始处理根据修改品牌状态的请求,参数:{}",id);
        brandService.setDisable(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/brand/{?}
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查找品牌")
    @ApiOperationSupport(order = 410)
    public JsonResult<BrandStandardVO> getStandardById(
            @PathVariable @Range
                    (min = 1L,message = "请提交有效的ID值!")
                    Long id){
        log.debug("开始处理根据ID:{}查询品牌列表的请求",id);
        BrandStandardVO queryResult = brandService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }
    
    // http://localhost:9080/brands
    @ApiOperation("品牌列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")

    public JsonResult<List<BrandListItemVO>> list(){
        List<BrandListItemVO> list = brandService.list();
        return JsonResult.ok(list);
    }




//    BrandStandardVO getStandardById(Long id);
}
